import { defineStore } from "pinia";
import { type ContentModel } from "@/api/discovery/integrated";
import {
    getFilterTopList,
    getHotTopList,
    getIntegratedTopList,
    getLatestTopList,
    getNewTopList,
} from "@/api/index/original";
import { type filterListType } from "@/api/discovery/filter";

export const useOriginalDataStore = defineStore({
    id: "originalDataStore",
    state: () => {
        return {
            // 数据
            integratedData: [] as ContentModel[],
            // 筛选
            filterData: [] as filterListType,
        };
    },
    actions: {
        // 1.综合榜单
        async getIntegratedDataAsync(page: number) {
            const res = await getIntegratedTopList(page);
            this.integratedData.push(...res.content);
        },
        // 2.热练榜单
        async getHotDataAsync(page: number) {
            const res = await getHotTopList(page);
            this.integratedData.push(...res.content);
        },
        // 3.新锐榜单
        async getNewDataAsync(page: number) {
            const res = await getNewTopList(page);
            this.integratedData.push(...res.content);
        },
        // 4.最新榜单
        async getLatestDataAsync(page: number) {
            const res = await getLatestTopList(page);
            this.integratedData.push(...res.content);
        },
        // 5.筛选数据
        async getFilterDataAsync() {
            this.filterData = await getFilterTopList();
        },
        // 6.load
        async loadData(isChecked: number) {
            if (isChecked === 1) {
                // 获取综合排序数据
                await this.getIntegratedDataAsync(1);
            } else if (isChecked === 2) {
                // 获取热练排序数据
                await this.getHotDataAsync(1);
            } else if (isChecked === 3) {
                // 获取新锐排序数据
                await this.getNewDataAsync(1);
            } else if (isChecked === 4) {
                // 获取最新排序数据
                await this.getLatestDataAsync(1);
            }
        },
    },
});
